import { bindActionCreators, type EnhancedStore, type ActionCreatorsMapObject } from '@reduxjs/toolkit'
import { useRef } from 'react'


export function useActionsHook<
    S extends EnhancedStore<any>,
    A extends ActionCreatorsMapObject<any>
>(store: S, actionCreators: A) {
    const { dispatch } = store;
    const actions = bindActionCreators(actionCreators, dispatch);
    const actionsRef = useRef<typeof actions>(); // 获得推导的类型

    // actionsRef.current?.setToken

    if (actionsRef.current) return actionsRef.current;
    actionsRef.current = actions;

    return actionsRef.current;
}

